
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace RSSRadio
{
	public partial class DownloadProgressPanel : UserControl
	{
		public DownloadProgressPanel(string title, string description)
		{
			InitializeComponent();
			
			this.LblTitle.Text = title;
			this.LblTitle.Width = this.Width - 5;

			this.LblDescription.Text = description;
			this.LblDescription.Width = this.Width - 5;

			this.LblProgress.Text = "Waiting  ";
			this.ProgressBar.Width = this.Width - LblProgress.Width - 10;
		}

		protected override void OnResize(EventArgs e)
		{
			this.ProgressBar.Width = this.Width - LblProgress.Width - 10;
			base.OnResize(e);
		}

		public void SetProgress(int percent, int kBps, int megsReceived, int totalMegs, int secondsRemaining)
		{
			this.ProgressBar.Value = percent;

			int minutesRemaining = secondsRemaining / 60;
			int remainderSeconds = secondsRemaining % 60;
			this.LblProgress.Text = megsReceived.ToString() + "/" + 
				totalMegs.ToString() + "MB " + kBps.ToString() + "K/s "
				+ minutesRemaining.ToString() + ":" + remainderSeconds.ToString("D2");

			if (percent == 100)
				LblProgress.Text = "Complete " + kBps.ToString() + "K/s";
		}

		private void pictureBox1_Click(object sender, EventArgs e)
		{
			foreach (PodcastDownloader2 downloader in Globals.ActivePodcastDownloaders)
			{
				if (downloader == this.Tag)
				{
					downloader.WantToCancel = true;
					ProgressBar.Value = 0;
					LblProgress.Text = "Canceled";
					break;
				}
			}
		}
	}
}
